cc.Class({
    extends: cc.Component,

    properties: {
        
    },

    // LIFE-CYCLE CALLBACKS:

    onLoad () {
        this.node.color = this.randomColor();
        this.node.setPosition(this.randomPos());
    },

    randomColor () {
        // get random color
        this.nextGoal = Math.floor(7*Math.random());
        //随机生成某种颜色
         if(this.nextGoal===0){return new cc.Color(255, 0, 0);}//red 
         if(this.nextGoal===1){return new cc.Color(0, 255, 0);}//green
         if(this.nextGoal===2){return new cc.Color(0, 0, 255);}//blue
         if(this.nextGoal===3){return new cc.Color(255, 192, 203);}//pink
         if(this.nextGoal===4){return new cc.Color(0, 0, 0);}//black
         if(this.nextGoal===5){return new cc.Color(255, 0, 255);}//purple
         if(this.nextGoal===6){return new cc.Color(255, 165, 0);}//orange

    },

    addScore (){
        //根据不同果实增加分数
        if(this.nextGoal===0){this.scoreNum+=50;}
        if(this.nextGoal===1){this.scoreNum+=100;}
        if(this.nextGoal===2){this.scoreNum+=200;}
        if(this.nextGoal===3){this.scoreNum+=300;}
        if(this.nextGoal===4){this.scoreNum+=400;}
        if(this.nextGoal===5){this.scoreNum+=500;}
        if(this.nextGoal===6){this.scoreNum+=600;}
    },

    randomPos () {
        let width = this.node.parent.width;
        let height = this.node.parent.height;
        let x = Math.round(Math.random()*width) - width/2;
        let y = Math.round(Math.random()*height) - height/2;
        return cc.v2(x, y);
    }
});
